package net.homeip.mmhg.util;

import org.joda.time.DateTime;

/**
 * Some tools for <code>DateTime</code>.
 * 
 * @author pilot
 */
public class DateUtil {
	
	/**
	 * Creates new instances of <code>DateTime</code> by merging of date and time
	 * @param date Date to set.
	 * @param time Time to set.
	 * @return new <code>DateTime</code> object, whose date will be equal Date and time - Time. 
	 */
	public static DateTime setTime(DateTime date, DateTime time) {
		DateTime dt = (date.getMillisOfDay() < time.getMillisOfDay()) ? date : date.plusDays(1);
		return new DateTime(dt.getYear(),
							dt.getMonthOfYear(),
							dt.getDayOfMonth(),
							time.getHourOfDay(),
							time.getMinuteOfHour(),
							time.getSecondOfMinute(),
							time.getMillisOfSecond());
	}
}
